package hot100;

import java.util.HashSet;
import java.util.Set;

public class detectCycle2 {
    public mergeKLists.ListNode detectCycle(mergeKLists.ListNode head) {
        Set<mergeKLists.ListNode> set = new HashSet<>();

        while(head != null) {
            if(!set.contains(head)) {
                set.add(head);
            }else {
                return head;
            }
            head = head.next;
        }
        return null;

    }
}
